IRCBot::Plugin.define "server" do
	help_string nil
	$server_socket = nil
	def command(user,target,message,usermask)
		if get_plugin('auth').is_auth_user?(usermask) then
			command = message.split[0]
			message = message.sub(command,"").strip
			
			case command
				when 'status'
					if $server_socket
						privmsg(target,'Server is online.')
					else
						privmsg(target,'Server is offline.')
					end
				when 'start'
					$server_socket = TCPServer.open(20000)
					privmsg(target,'Server is online.')
				when 'stop'
					$server_socket = nil
					privmsg(target,'Server is offline.')
			end
		end
	end
	def handle_input(input)
		input.puts "001 Authenticate"
		stuff = input.gets
		if stuff.downcase == 'quit' then
			input.puts '001 Goodbye'
			input.close
		else
			message = stuff
			command = message.split[0]
			message = message.sub(command,"").strip		
			if command.downcase == 'auth' then
				user = message.split[0]
				pass = message.split[1]
				if user == 'NieXS' and pass == '854600' then
					stillhere = true
				else
					stillhere = false
				end
			end
		end
		input.puts '001 Welcome'
		#stillhere = true
		while stillhere
			message = input.gets
			command = message.split[0].downcase
			message = message.sub(command,"").strip
			case command
				when 'quit'
					input.puts '001 Goodbye'
					input.close
				when 'quitirc'
					$ircbot.send("QUIT #{message}")
					input.puts '001 Finished.'
				else
					input.puts '002 Unknown command'
			end
		end
	end
end
